<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<script type="text/javascript">
	var zcPolicyDataGrid;
	$(function() {
		zcPolicyDataGrid = $('#zcPolicyDataGrid')
				.datagrid(
						{
							url : '${path}/zcPolicy/dataGrid',
							striped : true,
							rownumbers : true,
							pagination : true,
							singleSelect : true,
							idField : 'id',
							sortName : 'id',
							sortOrder : 'asc',
							pageSize : 20,
							pageList : [ 10, 20, 30, 40, 50, 100, 200, 300,
									400, 500 ],
							frozenColumns : [ [
									{
										width : '100',
										title : '慢性政策编码',
										field : 'id',
										sortable : true
									},
									{
										width : '100',
										title : '年度',
										field : 'runyear',
										sortable : true
									},
									{
										width : '100',
										title : '封顶线',
										field : 'maxLine',
										sortable : true
									},
									{
										width : '60',
										title : '报销比例',
										field : 'runRate',
										sortable : true
									},
								
									{
										field : 'action',
										title : '操作',
										width : 200,
										formatter : function(value, row, index) {
											var str = '';
											<shiro:hasPermission name="/zcPolicy/edit">
											str += $
													.formatString(
															'<a href="javascript:void(0)" class="zcPolicy-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="zcPolicyEditFun(\'{0}\');" >编辑</a>',
															row.id);
											</shiro:hasPermission>
											<shiro:hasPermission name="/zcPolicy/delete">
											str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
											str += $
													.formatString(
															'<a href="javascript:void(0)" class="zcPolicy-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="zcPolicyDeleteFun(\'{0}\');" >删除</a>',
															row.id);
											</shiro:hasPermission>
											return str;
										}
									} ] ],
							onLoadSuccess : function(data) {
								$('.zcPolicy-easyui-linkbutton-edit')
										.linkbutton({
											text : '编辑'
										});
								$('.zcPolicy-easyui-linkbutton-del')
										.linkbutton({
											text : '删除'
										});
							},
							toolbar : '#zcPolicyToolbar'
						});
	});

	/**
	 * 添加框
	 * @param url
	 */
	function zcPolicyAddFun() {
		parent.$.modalDialog({
			title : '添加',
			width : 700,
			height : 600,
			href : '${path}/zcPolicy/addPage',
			buttons : [ {
				text : '确定',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = zcPolicyDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
					var f = parent.$.modalDialog.handler
							.find('#zcPolicyAddForm');
					f.submit();
				}
			} ]
		});
	}

	/**
	 * 编辑
	 */
	function zcPolicyEditFun(id) {
		if (id == undefined) {
			var rows = zcPolicyDataGrid.datagrid('getSelections');
			id = rows[0].id;
		} else {
			zcPolicyDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.modalDialog({
			title : '编辑',
			width : 700,
			height : 600,
			href : '${path}/zcPolicy/editPage?id=' + id,
			buttons : [ {
				text : '确定',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = zcPolicyDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = parent.$.modalDialog.handler
							.find('#zcPolicyEditForm');
					f.submit();
				}
			} ]
		});
	}

	/**
	 * 删除
	 */
	function zcPolicyDeleteFun(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = zcPolicyDataGrid.datagrid('getSelections');
			id = rows[0].id;
		} else {//点击操作里面的删除图标会触发这个
			zcPolicyDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
		}
		parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
			if (b) {
				progressLoad();
				$.post('${path}/zcPolicy/delete', {
					id : id
				}, function(result) {
					if (result.success) {
						parent.$.messager.alert('提示', result.msg, 'info');
						zcPolicyDataGrid.datagrid('reload');
					}
					progressClose();
				}, 'JSON');
			}
		});
	}

	/**
	 * 清除
	 */
	function zcPolicyCleanFun() {
		$('#zcPolicySearchForm input').val('');
		zcPolicyDataGrid.datagrid('load', {});
	}
	/**
	 * 搜索
	 */
	function zcPolicySearchFun() {
		zcPolicyDataGrid.datagrid('load', $
				.serializeObject($('#zcPolicySearchForm')));
	}
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'north',border:false"
		style="height: 30px; overflow: hidden; background-color: #fff">
		<form id="zcPolicySearchForm">
			<table>
				<tr>
					<th>请输入年度:</th>
					<td><input name="id" placeholder="搜索条件" /></td>
					<td><a href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'fi-magnifying-glass',plain:true"
						onclick="zcPolicySearchFun();">查询</a> <a
						href="javascript:void(0);" class="easyui-linkbutton"
						data-options="iconCls:'fi-x-circle',plain:true"
						onclick="zcPolicyCleanFun();">清空</a></td>
				</tr>
			</table>
		</form>
	</div>

	<div data-options="region:'center',border:false">
		<table id="zcPolicyDataGrid" data-options="fit:true,border:false"></table>
	</div>
</div>
<div id="zcPolicyToolbar" style="display: none;">
	<shiro:hasPermission name="/zcPolicy/add">
		<a onclick="zcPolicyAddFun();" href="javascript:void(0);"
			class="easyui-linkbutton"
			data-options="plain:true,iconCls:'fi-page-add'">添加</a>
	</shiro:hasPermission>
</div>